#!/usr/bin/env node

const http = require('http'),
  fs = require('fs'),
  mem = require('memory-format'),
  { join } = require('path');
const { console } = require('inspector');

http.createServer((req, res) => {
  console.time('TEST');
  let file = join(__dirname, req.url);

  if (!fs.existsSync(file)) {
    res.end(`${req.url} not exists!`)
    return;
  }

  fs.readFile(file, (err, data) => {
    if (err) {
      res.end('something wrong!');
    } else {
      res.end(data);
    }
  });
}).listen(8080);